﻿<html>
<head>

   <title>JsonRpc 2.0 - Test</title>

   <script type="text/javascript" src="ext-core.js"></script>
   <script type="text/javascript" src="JsonRpc.js"></script>
   <script type="text/javascript" src="TestService.ashx"></script>

</head>
 
<body>

<div>JsonRpc 2.0 - Test</div>
 
    <script type="text/javascript">
  
        var service = new Client.TestService();
        service.$url = 'http://localhost:5050/TestService1.ashx';
        //create the callback handlers
        service.SumCompleted = function (response)
        {
            if (response.error)
            {
                alert(response.error.code)
            }
            else
            {
                alert(response.result + "\r\nFrom SumCompleted");
            }
        }

        service.getMessageSuccess = function (result)
        {
            alert(result);
        }

        service.getMessageFailed = function (error)
        {
            alert(error.message);
        }


        service.TestManyParamsSuccess = function (result)
        {
            alert(result);
        }

        //call the methods on the server
        //service.Sum(10, 15); //id=0
        //service.getMessage("Allex"); //id=1
        //service.TestManyParams("param1", "param2", "param3", "param4", 135, { success: function (result) { alert(result + "\r\nfrom other"); }, v:"Nu trebuie sa fie" });

        var TestObject = {
            v: 100,
            ShowResult: function (result)
            {
                alert(this.v + result + "\r\nFrom TestObject.ShowResult");
            },
           ShowResponse: function (response)
            {
                alert(this.v + response.result + "\r\nFrom TestObject.ShowResponse");
            }

        };
        //call the same methods but in a batch
        service.$call({
            Sum: [10, 15,
            {
                callback: function (response) { alert(response.result + "simple callback"); },
                events: [
                { success: TestObject.ShowResult, scope: TestObject },
                { callback: TestObject.ShowResponse, scope: TestObject }
                    ]
            }],
            getMessage: ["Allex", { success: TestObject.ShowResult, scope: TestObject}] //id=3
        });


    </script>
  
</body>
</html>


